@extends('layouts.app', ['active' => 4])

@section('title')人员列表 -
@endsection
@section("style")

@endsection
@section('content')
<?php
extract($filter);
?>
    <div class="panel panel-default">
        <div class="panel-heading">

            <i class="fa fa-align-justify"></i> 人员列表
        <!--<a  href="{{ url('person/?') }}@foreach ($filter as $k => $v){{$k}}={{$v}}&@endforeach&action=print&per_page={{$per_page}}"  ><i class="fa fa-print" aria-hidden="true"></i> 打印</a>-->
            <a  href="#" id="list_print"><i class="fa fa-print" aria-hidden="true"></i> 打印</a>
            <a  href="{{ url('person/excel?') }}@foreach ($filter as $k => $v){{$k}}={{$v}}&@endforeach&action=excel&per_page={{$per_page}}" id="list_print"><i class="fa fa-file-excel-o" aria-hidden="true"></i> 导出Excel</a>

            @include('person.menu',['active' => 2])
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12 text-right" style="border-bottom:1px solid #ccc;margin-bottom:10px;">

                    <form class="form-inline" action="" id="search_form" method="GET">
                        <div class="form-group">
                            <p>
                                <select name="year" id="year" class="form-control input-sm">
                                    <option value="" @if ($filter['year'] === '') selected="selected"@endif>所有年份</option>
                                    @foreach ($years as $k => $y)
                                        <option value="{{$y}}" @if ($filter['year'] == $y) selected="selected"@endif>{{$y}}</option>
                                    @endforeach
                                </select>

                                <select name="is_the_city" id="is_the_city" class="form-control input-sm">
                                    <option value='all' @if ($filter['is_the_city'] === 'all') selected="selected"@endif>户籍</option>
                                    <option value="1" @if ($filter['is_the_city']  === '1') selected="selected"@endif>本市</option>
                                    <option value="0" @if ($filter['is_the_city']  === '0') selected="selected"@endif>他市</option>
                                </select>
                                <select name="five_saw_time" id="five_saw_time" class="form-control input-sm">
                                    <option value='all' @if ($filter['five_saw_time'] === 'all') selected="selected"@endif>是否离开</option>
                                    <option value='1' @if ($filter['five_saw_time'] === '1') selected="selected"@endif>在本市</option>
                                    <option value="0" @if ($filter['five_saw_time']  === '0') selected="selected"@endif>已离开</option>
                                </select>
                                <input type="text" class="form-control input-sm" name="start_time" onclick="WdatePicker()" value="{{$filter['start_time']}}" id="start_time" size="12" readonly style="background-color:#fff"  placeholder="来我市时间"/>
                                <input type="text" class="form-control input-sm" name="end_time" onclick="WdatePicker()" value="{{$filter['end_time']}}" id="end_time" size="12" readonly style="background-color:#fff"  placeholder="离开我市时间"/>
                                <input type="text" class="form-control input-sm" name="keyword" value="{{$filter['keyword']}}"id="keyword" placeholder="姓名 | 手机号 | 身份证号"/>
                            </p>
                            <p>
                                <button type="submit" class="btn btn-primary btn-sm search-btn" title="搜索"><i class="fa fa-search" aria-hidden="true"></i> 搜索</button>
                                <button type="button" class="btn btn-default btn-sm search-btn" onclick="window.location.href='{{ url('person/') }}'" title="重置"><i class="fa fa-refresh" aria-hidden="true"></i> 重置</button>

                            </p>
                        </div>


                    </form>
                </div>

            </div>
            <div class="row" style="margin-bottom:10px">
                <div class="col-md-2 text-left" style="">
                    <div class="form-inline" action="{{ url('person/recycle') }}" >
                        <input type="text" class="form-control input-sm" style="display: none"/>
                        <button type="button " id="batch_delete" data-toggle="modal" class="btn btn-default btn-sm" data-action="{{url('person/recycle')}}" data-target="#delete_modal"><i class="fa fa-trash-o"></i>  移至回收站</button>
                    </div>
                </div>

                <div class="col-md-10 text-right" style="">
                    <button type="button"  data-toggle="modal" data-action="" class="btn btn-default btn-sm" style="visibility: hidden"><i class="fa fa-trash-o"></i>  占位符</button>
                    共 <strong>{{$persons->total('id')}} </strong>人，每页 &nbsp;
                    <select id="per_page" class="input-sm">
                        <option value="15" @if ($per_page == 15) selected="selected"@endif>15</option>
                        <option value="20" @if ($per_page == 20) selected="selected"@endif>20</option>
                        <option value="50" @if ($per_page == 50) selected="selected"@endif>50</option>
                        <option value="100" @if ($per_page == 100) selected="selected"@endif>100</option>
                    </select>
                </div>
            </div>

            @if ($persons->total() != 0)
                <div class="table-responsive" id="person_list">
                    <table class="table table-hover table-striped table-condensed table-bordered" >
                        <thead class="">
                        <tr>
                            <th class="hidden-print">
                                <input type="checkbox" id="select_all" class="hidden-print"/>
                            </th>
                            <th >ID</th>
                            <th>照片</th>
                            <th>姓名</th>
                            <th>本市户籍</th>
                            <th>身份证</th>
                            <th>所在地</th>
                            <th>到我市时间</th>
                            <th>手机号</th>
                            <th style="width:160px;text-align:center" class="hidden-print">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($persons as $person)
                            <tr>
                                <td class="hidden-print">
                                    <input type="checkbox" name="ids" value="{{ $person->id }}" class="hidden-print"/>
                                    <span class="print-show">{{ $person->id }}</span>
                                </td>
                                <td>
                                    {{ $person->id }}
                                </td>

                                <td>
                                    <a href="{{ url('person/'.$person->id) }}" class="hidden-print" style="position: relative">
                                        <img src="{{ url('/') }}/@if ($person->avatar != ''){{ $person->avatar }}@else{{  'img/avatar_default.png' }}@endif"  style=" height:30px;width:30px;" class="img-thumbnail img-circle img-avatar-small" alt="{{ $person->name }}"/>
                                        <img style="display:none;position:absolute;z-index:1100;top:-50px;left:40px;width:60px;max-width:128px" src="{{ url('/') }}/@if ($person->avatar != ''){{ $person->avatar }}@else{{  'img/avatar_default.png' }}@endif" class="img-thumbnail" alt="{{ $person->name }}"/>
                                    </a>
                                    <a href="#">
                                        <img class="print-show img-thumbnail img-circle img-avatar-small" src="{{ url('/') }}/@if ($person->avatar != ''){{ $person->avatar }}@else{{  'img/avatar_default.png' }}@endif"  style="overflow: hidden; height:30px;width:30px;"  alt="{{ $person->name }}"/>
                                    </a>
                                </td>
                                <td>
                                    <div class="hidden-print" style="position: relative">
                                        <a href="{{ url('person/'.$person->id) }}" class="hidden-print name-avatar-hover">{{ $person->name }}</a>
                                        <img style="display:none;position:absolute;z-index:1100;top:-50px;left:80px;width:60px;max-width:128px" src="{{ url('/') }}/@if ($person->avatar != ''){{ $person->avatar }}@else{{  'img/avatar_default.png' }}@endif" class="img-thumbnail hidden-print" alt="{{ $person->name }}"/>
                                    </div>
                                    <a class="print-show"> {{ $person->name }} </a>

                                </td>
                                <td>
                                    @if ($person->is_the_city == 1) <strong style="color:#5cb85c" class="print-show">✔</strong>
                                    @else
                                        <strong style="color:#d9534f" class="print-show">✘</strong>
                                    @endif
                                    <span class="hidden-print">
                                      @if ($person->is_the_city == 1)

                                            <a href="" class="is_city_link" style="color:#5cb85c"  title="本市" ><strong style="color:#5cb85c">✔</strong></a>
                                            <form action="person/isCity" class="is_city_form"  method="POST" style="display: none;" id="is_city_form_{{$person->id}}">
                                              {{ csrf_field() }}
                                                <input type="hidden" name="id" id="is_city_{{$person->id}}" value="{{$person->id}}">
                                              <input type="hidden" name="type" id="is_city_type_{{$person->id}}" value="0"/>
                                          </form>
                                        @else


                                            <a href="" class="is_city_link" style="color:#c12e2a"  title="非本市"><strong style="color:#d9534f">✘</strong></a>
                                            <form action="person/isCity" class="is_city_form"  method="POST" style="display: none;" id="is_city_form_{{$person->id}}">
                                              {{ csrf_field() }}
                                                <input type="hidden" name="id" id="is_city_{{$person->id}}" value="{{$person->id}}"/>
                                              <input type="hidden" name="type" id="is_city_type_{{$person->id}}" value="1"/>
                                          </form>
                                        @endif
                                      </span>

                                </td>
                                <td>{{ $person->id_number }}</td>
                                <td>{{ $person->temp_addr }}</td>
                                <td>{{ $person->five_saw_time==0?'已离开':date('Y-m-d', $person->five_saw_time) }}</td>
                                <td>{{ $person->phone }}</td>
                                <td class="hidden-print" style="text-align: center">
                                    <a href="{{ url('person/'.$person->id) }}" title="查看"><i class="fa fa-search-minus"></i></a>&nbsp;&nbsp;&nbsp;
                                    <a href="{{ url('person/'.$person->id.'/edit') }}" title="编辑"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:;" class="model_recycle" data-id="{{$person->id}}" data-toggle="modal"  data-target="#delete_modal" title="移至回收站"><i class="fa fa-trash-o"></i> </a>
                                <!--
                                    <a href="javascript:;" data-toggle="modal" data-action="{{ url('person/'.$person->id) }}" data-target="#delete_modal">删除</a>
                                  -->
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div style="text-align:right;padding:0 0 10px;">

                </div>
                @if ($persons->total() >= $per_page)
                    <div style="float:right">
                        <div class="pull-left">
                            {{ $persons->appends([
                                'action' => $action,
                                'keyword' => $keyword,
                                'is_the_city' => $is_the_city,
                                 'start_time' => $start_time,
                                 'end_time' => $end_time,
                                 'per_page' => $per_page,
                                 'year' => $year,
                             ])->links() }}

                        </div>
                    <!--
                        <form action="" method="get" style="display:inline">
                            &nbsp;<input type="text" value="{{$page}}" size="3" name="page" style="padding:4px 0 ;"  /> 页
                            <input type="hidden" name="action" value="{{$action}}"/>
                            <input type="hidden" name="keyword" value="{{$keyword}}"/>
                            <input type="hidden" name="is_the_city" value="{{$is_the_city}}"/>
                            <input type="hidden" name="start_time" value="{{$start_time}}"/>
                            <input type="hidden" name="end_time" value="{{$end_time}}"/>
                            <input type="hidden" name="per_page" value="{{$per_page}}"/>
                            <input type="hidden" name="year" value="{{$year}}"/>

                            <button type="submit"  class="btn btn-primary page_jump">跳转</button>
                        </form>
                        -->
                    </div>

                @endif

        </div>
    </div>
    @else
        <p style="text-align:center;border:1px solid #ccc;border-radius: 5px;padding:10px;font-size:14px">没有人员信息</p>
    @endif



@endsection
@section('modal')
    <div class="modal fade" tabindex="-1" role="dialog" id="delete_modal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">确认</h4>
                </div>
                <div class="modal-body">
                    <p class="text-center">确定移动至回收站吗?</p>
                </div>
                <div class="modal-footer">
                    <form action="person/recycle" method="POST" style="display: inline;" id="model_form">
                        {{ csrf_field() }}
                        <input type="hidden" name="id" id="recycle_id" value="">
                        <button type="submit" class="btn btn-primary">是</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">否</button>

                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
@endsection
@section('script')
    <script type="text/javascript" src="{{ asset('js/mouse.js')}}"></script>
    <script type="text/javascript" src="{{ asset('plugin/My97DatePicker/WdatePicker.js')}}"></script>

    <script type="text/javascript" src="{{ asset('plugin/print/jQuery.print.js') }}"></script>
    <script>
        $(function(){
            $('#batch_delete').click(function(){
                var ids = [];
                $("input[name='ids']").each(function() {
                    if ($(this).prop('checked') == true) {
                        ids.push($(this).val());
                    }
                });
                ids = ids.join(",");
                $('#recycle_id').val(ids);
                if (ids == '') {
                    alert('请至少选择一个人员');
                    return false;
                }


            });
            $('#select_all').change(function(){
                //alert($(this).prop("checked"));
                $("input[name='ids']").prop("checked", $(this).prop("checked"));
                var ids = [];
                $("input[name='ids']").each(function() {
                    if ($(this).prop('checked') == true) {
                        ids.push($(this).val());
                    }
                });
                ids = ids.join(",");
                //alert(ids);
                //$('#batch_delete').attr("data-action", "{{ url('person/recycle') }}/" + ids);
                $('#recycle_id').val(ids);


            });
            $("input[name='ids']").change(function(){
                var ids = [];
                $("input[name='ids']").each(function() {
                    if ($(this).prop('checked') == true) {
                        ids.push($(this).val());
                    }
                });
                ids = ids.join(",");
                //alert(ids);
                //$('#batch_delete').attr("data-action", "{{ url('person/recycle') }}/" + ids);
                //alert(ids);
                $('#recycle_id').val(ids);
            });
            $('.model_recycle').click(function(){
                var id = $(this).attr("data-id");
                $('#recycle_id').val(id);
            });
        });

        $('#delete_modal').on('show.bs.modal', function (event) {

            var button = $(event.relatedTarget) // Button that triggered the modal
            var action = button.data('action') // Extract info from data-* attributes

            var modal = $(this)
            modal.find('form').attr('action', action);
        });
    </script>

    <script>
        $(function () {


            $('#per_page').change(function(){
                var per_page = $(this).val();
                var url =   '?@foreach ($filter as $k => $v){{$k}}={{$v}}&@endforeach';
                window.location.href = '{{ url('person/') }}' + url + 'per_page=' + per_page;
            });
        });
    </script>


    <script>

        // 切换是否本市
        $(".is_city_link").click(function(){
            //$("p").slideToggle();
            $(this).next().submit();
            return false;
        });
    </script>



    <script>
        $(":input[name='page']").click(function(){
            $(this).val('');
        }).blur(function(){
            if ($(this).val() == '{{$page}}' || $(this).val() == '')
                $(this).val('{{$page}}');
            if ($(this).val() > '{{$persons->lastPage()}}'){
                alert('不能大于{{$persons->lastPage()}}页');
                $(this).val('{{$persons->lastPage()}}');
                return false;
            }
        });
        $('.page_jump').click(function(){
            //var page = $(":input[name='page']").val();
            if(!/^\d+$/.test($(":input[name='page']").val())) {
                alert("必须是整数");
                $(":input[name='page']").val('1');
                return false;
            }
//        var page_1 = parseInt(page) - 1;
//        alert(page_1);
//        return false;
            if ($(":input[name='page']").val() > {{$persons->lastPage()}}){
                //alert(page);
                alert('不能大于{{$persons->lastPage()}}页');
                //$(":input[name='page']").val('{{$persons->lastPage()}}');
                return false;
            }
        });

        // 判断是否为数字
        function isNumber(val){

            var regPos = /^\d+(\.\d+)?$/; //非负浮点数
            //var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
            if(regPos.test(val)){
                return true;
            }else{
                return false;
            }

        }
    </script>


    <script type="text/javascript">
        //<![CDATA[
        jQuery(function($) { 'use strict';

            $("#list_print").on('click', function() {
                //Print ele4 with custom options
                $("#person_list").print({
                    //Use Global styles
                    globalStyles : true,
                    //Add link with attrbute media=print
                    mediaPrint : true,
                    //Custom stylesheet

                    //Print in a hidden iframe
                    iframe : false,
                    //Don't print this
                    noPrintSelector : ".hidden-print",
                    //Add this at top
                    prepend : "",
                    //Add this on bottom
                    append : "",
                    //Log to console when printing is done via a deffered callback
                    deferred: $.Deferred().done(function() { console.log('Printing done', arguments); })
                });
            });
            // Fork https://github.com/sathvikp/jQuery.print for the full list of options
            //$("#list_print").click();
        });
        //]]>

    </script>
    <script>
        $(function(){
            $("#is_the_city,#year,#five_saw_time").change(function(){
                $("#search_form").submit();
            });

            $('.img-avatar-small').mouseover(function(){
                $(this).next().show();
            }).mouseout(function(){
                $(this).next().hide();
            });

            $('.name-avatar-hover').mouseover(function(){
                $(this).next().show();
            }).mouseout(function(){
                $(this).next().hide();
            });
        })
    </script>
@endsection
